package com.test.threadtest;

import java.util.concurrent.CountDownLatch;

/**
 * Created by jl on 2016/8/7.
 */
public class Worker extends Thread {
    private String name;
    private int workTiem;
    private CountDownLatch latch;

    public Worker(String n, int w, CountDownLatch latch) {
        this.name = n;
        this.workTiem = w;
        this.latch = latch;
    }

    @Override
    public void run() {
        System.out.println("worker " + name + "do work begin at " + System.currentTimeMillis());
        this.doWork();
        System.out.println(name + "工作完成在" + System.currentTimeMillis());
        latch.countDown();
    }

    private void doWork() {
        try {
            Thread.sleep(workTiem);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
